package mobi.zeedev.flyingsaucer.common.DataModule.tree;

/**
 * User: James
 * Date: 12/28/10
 * Time: 2:16 AM
 */
public class DatabaseNode extends Node<Void> implements DatabaseAttribute {


    @Override
    public String toString() {
        return "<" + type + "," + columnName + "," + value + ">";
    }

    @Override
    public Object getValue() {
        return value;
    }

    @Override
    public DatabaseType getType() {
        return type;
    }

    DatabaseType type;
    Object value;
    Object columnName;

    public DatabaseNode setType(DatabaseType type) {
        this.type = type;
        return this;
    }

    public DatabaseNode setValue(Object value) {
        this.value = value;
        return this;
    }

    public DatabaseNode setColumnName(Object columnName) {
        this.columnName = columnName;
        return this;
    }

    public DatabaseNode() {
        super();
    }

    @Override
    public Object getColumnName() {
        return columnName;
    }

    public DatabaseNode addAttribute(Object columnName, Object attributeValue) {
        addChild(DatabaseNode.EntryNode(columnName,attributeValue));
        return this;
    }

    public static DatabaseNode TableNode(Object tableName) {
        return new DatabaseNode().setType(DatabaseType.TABLE).setValue(tableName);
    }

    public static DatabaseNode TableNode() {
        return new DatabaseNode().setType(DatabaseType.TABLE);
    }

    public static DatabaseNode EntryNode() {
        return new DatabaseNode().setType(DatabaseType.ATTRIBUTE_ENTRY);
    }

    public static DatabaseNode EntryNode(Object columnName, Object value) {
        return new DatabaseNode().setType(DatabaseType.ATTRIBUTE_ENTRY).setColumnName(columnName).setValue(value);
    }

    public static DatabaseNode PrimaryKeyNode() {
        return new DatabaseNode().setType(DatabaseType.PRIMARY_KEY);
    }

    public static DatabaseNode PrimaryKeyNode(Object columnName, Object value) {
        return new DatabaseNode().setType(DatabaseType.PRIMARY_KEY).setColumnName(columnName).setValue(value);
    }


}
